﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HitachiLib.Data;

namespace HitachiApp.Model.Manage
{
    public class AccessToggleControlModel : INotifyPropertyChanged
    {
        public const int ProjectReadAccess = 0x01;
        public const int ProjectWriteAccess = 0x02;
        public const int ResourceReadAccess = 0x04;
        public const int ResourceWriteAccess = 0x08;
        public const int ScheduleReadAccess = 0x10;
        public const int ScheduleWriteAccess = 0x20;
        
        private String desc;
        private int mask;
        private ProjectResourceRelation relation;
        private ProjectResourceRelationControlModel parent;

        public String Desc
        {
            get { return desc; }
            set {
                desc = value;
                RaisePropertyChanged("Desc");
            }
        }

        public ProjectResourceRelation Relation
        {
            get { return relation; }
            set {
                relation = value;
                RaisePropertyChanged("Access");
            }
        }

        public Boolean Access
        {
            get
            {
                if (relation != null)
                    return (mask & relation.Data.RelationFlag) > 0;
                else
                    return false;
            }
            set
            {
                if (value)
                {
                    relation.Data.RelationFlag |= mask;
                }
                else
                {
                    relation.Data.RelationFlag &= ~mask;
                }
                RaisePropertyChanged("Access");
            }
        }

        public void Update()
        {
            parent.Update();
        }

        public AccessToggleControlModel(int mask, String desc, ProjectResourceRelation relation, ProjectResourceRelationControlModel prrcm)
        {
            this.mask = mask;
            this.desc = desc;
            this.relation = relation;
            parent = prrcm;
        }

        #region PropertChanged Block
        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
        #endregion
    }
}
